//
//  YTStashForewarningDetailsHeaderview.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/11/15.
//

#import "YTStashForewarningDetailsHeaderview.h"

@interface YTStashForewarningDetailsHeaderview ()

@property (nonatomic ,strong) UIImageView * productImg;
@property (nonatomic ,strong) UILabel * name;
@property (nonatomic ,strong) UILabel * type;
@property (nonatomic ,strong) UILabel * categoryName;
@property (nonatomic ,strong) UILabel * productBrand;
@property (nonatomic ,strong) UILabel * productNorms;
@property (nonatomic ,strong) UILabel * expiratDate;

@end

@implementation YTStashForewarningDetailsHeaderview


+ (instancetype)initview{
    YTStashForewarningDetailsHeaderview * view = [YTStashForewarningDetailsHeaderview new];
    view.clipsToBounds = YES;
    view.backgroundColor = UIColor.whiteColor;
    [view newUI];
    return view;
}
- (void)newUI{
    
    UIImageView * productImg = kimageView(@"tangkou_photo");
    self.productImg = productImg;
    [DTKTool YJ:kwt(4) andView:productImg];
    [self addSubview:productImg];
    [productImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.width.height.offset(kwt(66));
        make.top.offset(kwt(16));
    }];
    
    
    UILabel * name = [DTKTool labelWithText:@"--" andFont:kCFont(17) andTextColor:KcolorHex(@"#222222")];
    self.name = name;
    name.numberOfLines = 2;
    [self addSubview:name];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(16));
        make.left.offset(kwt(92));
        make.right.offset(kwt(-12));
    }];
    
    UILabel * type = [DTKTool labelWithText:@"--" andFont:kCFont(13) andTextColor:UIColor.whiteColor];
    self.type = type;
    type.textAlignment = NSTextAlignmentCenter;
    type.backgroundColor = KcolorHex(@"#FF9215");
    [DTKTool YJ:kwt(3) andView:type];
    [self addSubview:type];
    [type mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(64));
        make.left.offset(kwt(92));
        make.width.offset(kwt(67));
        make.height.offset(kwt(21));
    }];
    
    UIView * line = [UIView new];
    line.backgroundColor = KcolorHex(@"#D5D5D5");
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(95));
        make.height.offset(0.5);
        make.left.offset(kwt(12));
        make.right.offset(kwt(-12));
    }];
    
    UILabel * temp1 = [DTKTool labelWithText:@"物品品类" andFont:kFont(16) andTextColor:KcolorHex(@"#787A79")];
    [self addSubview:temp1];
    [temp1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(109));
        make.height.offset(kwt(16));
        make.left.offset(kwt(12));
    }];
    
    UILabel * categoryName = [DTKTool labelWithText:@"--" andFont:kFont(16) andTextColor:KcolorHex(@"#222222")];
    [self addSubview:categoryName];
    self.categoryName = categoryName;
    categoryName.numberOfLines = 0;
    [categoryName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(temp1);
        make.left.offset(kwt(92));
        make.width.offset(kwt(270));
        make.height.offset(kwt(16));
    }];
    
    UILabel * temp2 = [DTKTool labelWithText:@"物品品牌" andFont:kFont(16) andTextColor:KcolorHex(@"#787A79")];
    [self addSubview:temp2];
    [temp2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(categoryName.mas_bottom).offset(kwt(15));
        make.height.offset(kwt(16));
        make.left.offset(kwt(12));
    }];
    
    UILabel * productBrand = [DTKTool labelWithText:@"--" andFont:kFont(16) andTextColor:KcolorHex(@"#222222")];
    [self addSubview:productBrand];
    self.productBrand = productBrand;
    productBrand.numberOfLines = 0;
    [productBrand mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(temp2);
        make.left.offset(kwt(92));
        make.width.offset(kwt(270));
        make.height.offset(kwt(16));
    }];
    
    UILabel * temp3 = [DTKTool labelWithText:@"物品规格" andFont:kFont(16) andTextColor:KcolorHex(@"#787A79")];
    [self addSubview:temp3];
    [temp3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(productBrand.mas_bottom).offset(kwt(15));
        make.height.offset(kwt(16));
        make.left.offset(kwt(12));
    }];
    
    UILabel * productNorms = [DTKTool labelWithText:@"--" andFont:kFont(16) andTextColor:KcolorHex(@"#222222")];
    [self addSubview:productNorms];
    self.productNorms = productNorms;
    productNorms.numberOfLines = 0;
    [productNorms mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(temp3);
        make.left.offset(kwt(92));
        make.width.offset(kwt(270));
        make.height.offset(kwt(16));
    }];
    
    
}

- (void)setModel:(YTStashForewarningModel *)model{
    _model = model;
    [self.productImg LZsetImageWithImagePath:model.productImg placeholderImage:[UIImage imageNamed:@"tangkou_photo"]];
    if(model.type == 1){//库存不足
        self.type.text = @"库存不足";
        self.type.backgroundColor = KcolorHex(@"#FF9215");
    } else if(model.type == 2){//超出库存
        self.type.text = @"超出库存";
        self.type.backgroundColor = KcolorHex(@"#FE5402");
    }
    self.name.text = model.name;
    self.categoryName.text = model.categoryName;
    [self.categoryName mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.categoryNameH);
    }];
    self.productBrand.text = model.productBrand;
    [self.productBrand mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.productBrandH);
    }];
    self.productNorms.text = model.productNormsStr;
    [self.productNorms mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.productNormsStrH);
    }];
    self.expiratDate.text = model.expiratDate;
    if(model.expiratDate.length < 1){
        self.expiratDate.text = @"-";
    }
    [self.expiratDate mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.expiratDateH);
    }];
    
    
    
}
@end
